package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.esm.model.Department_lxy;
import com.esm.service.SelectDepartmentService_lxy;
import com.esm.serviceimpl.SelDepSerImpl_lxy;


import net.sf.json.JSONObject;
/**
 * 这是一个查询部门Controller
 * @author LiuXingYu
 *
 */
public class SelectDepartmentController_lxy extends HttpServlet{
	SelectDepartmentService_lxy selDepSer= new SelDepSerImpl_lxy();
	  @Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doGet(req, resp);
	}
	  @Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		     resp.setCharacterEncoding("utf8");
	    	 PrintWriter pw=resp.getWriter();
	    	 int page =Integer.parseInt(req.getParameter("page"));
	    	 
	    	 int rows =Integer.parseInt(req.getParameter("rows"));
	    	
	    	 int total=selDepSer.getDeparmentCount();
	    	 List<Department_lxy> deparments=selDepSer.getDeparments(page, rows);
	    	 JSONObject j=new JSONObject();
	    	 j.put("total", total);
	    	 j.put("rows", deparments);
	    	 pw.write(j.toString());
	    	 pw.flush();
	    	 pw.close();
	    	
	}
}
